<?php
$res = http_post('https://developer.toutiao.com/auth/entity/update_basic_auth', [
    "access_token" => getAccessToken(),
    "appid" => "ttdd96ab2b42a07b6d01",
    "merchant_entity_id" => "E_7383974744783110194",
    "entity_name" => "萍乡市蓝盾实业有限公司机动车驾驶员培训中心",
    "enterprise" => [
        "certificate_id" => "91360301680923596P",//营业执照id
        "certificate_materials" => [
            [
                "material_type" => 1007,
                "material_expiretime" => "长期有效",
                "material_paths" => [
                    "certification/resource/98b726493b336da09f8b02bdadc68d8a"
                ]
            ]
        ],
        "legal_person" => [
            "name" => "刘钢",
            "id_number" => "360302197707010513",
            "expire_time" => "2028-05-06",
            "front_path" => "certification/resource/02995b984b54f02bb09b51ede033bf41",
            "back_path" => "certification/resource/c32c91f43e30329b55031512f3d7fc94"
        ]
    ]

]);

echo $res;
exit;
function get_access_token()
{
    $access_token = json_decode(http_post("https://developer.toutiao.com/api/apps/v2/token", [
        "appid" => "ttdd96ab2b42a07b6d01",
        "grant_type" => "client_credential",
        "secret" => "028db66bdff3fa44cad6f2fafa1faa3d6571b3b4"
    ]), true)['data']['access_token'];
    return $access_token;
}
function getAccessToken()
{
    //检测文件是否存在
    $file = 'access_token.txt';
    if (file_exists($file)) {
        //获取文件的最后修改时间
        $mtime = filemtime($file);
        //获取当前时间
        $now = time();
        //判断是否过期
        if (($now - $mtime) < 300) {
            //未过期，直接读取文件内容
            $access_token = file_get_contents($file);
            return $access_token;
        } else {
            $access_token = get_access_token();
            file_put_contents($file, $access_token);
            return $access_token;

        }
    } else {
        $access_token = get_access_token();
        file_put_contents($file, $access_token);
        return $access_token;
    }
}
function http_post($url, $data)
{
    $postdata = json_encode($data);
    // echo ($postdata);
    // exit;



    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/json',
            'content' => $postdata,
            'timeout' => 15 * 60
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}